<template>
  <div class="userBox bg-f2" id="uploadtu8">
    <div class="bg-fff">
      <!-- <joint-selection :JointSelection="JointSelection" @guanbi="pingguanbi($event)"></joint-selection> -->
      <el-breadcrumb separator-class="el-icon-arrow-right" class="pAll">
        <el-breadcrumb-item>
          <span @click="goBack">{{ url === 'networkAccessList' ? '主机备案列表' : '资产管理' }}</span>
        </el-breadcrumb-item>
        <el-breadcrumb-item>{{ url === 'networkAccessList' ? '资产登记' : '编辑资产' }}</el-breadcrumb-item>
      </el-breadcrumb>
      <el-form class="pAll" :model="ruleForm" :rules="rules" ref="ruleForm" label-width="130px" v-loading="loading" :validate-on-rule-change="false">
        <el-row>
          <el-col :span="2">
            <span class="title">资产信息：</span>
          </el-col>
          <el-col :span="8">
            <el-form-item label="资产名称:" prop="ZCMC">
              <el-input v-model.trim="ruleForm.ZCMC" clearable placeholder="资产名称"></el-input>
            </el-form-item>
            <el-form-item label="设备序列号:" prop="SBXLH">
              <el-input v-model.trim="ruleForm.SBXLH" disabled clearable placeholder="设备序列号"></el-input>
            </el-form-item>
            <el-form-item label="辖区(安装地址):" prop="XQBM">
              <!-- <el-input v-model.trim="ruleForm.XQBM" clearable placeholder="辖区" disabled></el-input> -->
              <el-cascader :options="addressOptions" v-model.trim="ruleForm.XQBM" disabled ref="cascaderList" class="inputSelect" style="margin-right: 10px; width: 100%" clearable></el-cascader>
            </el-form-item>
            <el-form-item label="详细地址:">
              <el-input type="textarea" disabled :rows="4" resize="none" show-word-limit :maxlength="100" v-model.trim="ruleForm.XXDZ" placeholder="请输入设备安装详细地址信息"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8" :offset="2">
            <el-form-item label="资产状态:" prop="type">
              <el-radio-group v-model.trim="ruleForm.ZCZT">
                <el-radio label="1">使用中</el-radio>
                <el-radio label="2">停用</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="资产坐标(经度/纬度):" prop="JWD">
              <el-input clearable v-model.trim="ruleForm.JWD" placeholder="00.000000，000.000000" class="inputSelect2"></el-input>
            </el-form-item>
            <el-form-item label="IP地址:" prop="IP">
              <el-input v-model.trim="ruleForm.IP" clearable placeholder="设备IP地址"></el-input>
            </el-form-item>
            <el-form-item label="资产图片:">
              <el-upload
                ref="upload"
                action="#"
                accept=".jpg, .jpeg, .png, .JPG, .JPEG, .PNG"
                list-type="picture-card"
                :auto-upload="false"
                :on-change="lalal"
                :file-list="fileList"
                :on-preview="handlePictureCardPreview"
                :on-remove="handleRemove"
              >
                <i class="el-icon-plus"></i>
              </el-upload>
              <el-dialog :visible.sync="dialogVisible">
                <img width="100%" :src="dialogImageUrl" alt />
              </el-dialog>
              <span class="el-upload__tip">只能上传jpg/png文件，且不超过2M</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="2">
            <span class="title">厂家信息：</span>
          </el-col>
          <el-col :span="8">
            <el-form-item label="所属厂家:" prop="CJ">
              <el-select v-model.trim="ruleForm.CJ" :no-data-text="tiText3" clearable filterable disabled placeholder="选择厂家" class="inputSelect">
                <el-option v-for="item in cjOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="品牌:" prop="PP">
              <el-select v-model.trim="ruleForm.PP" :no-data-text="tiText4" clearable filterable disabled placeholder="品牌" class="inputSelect">
                <el-option v-for="item in ppmcOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="型号:" prop="XH">
              <el-input v-model.trim="ruleForm.XH" disabled clearable placeholder="型号"></el-input>
            </el-form-item>
            <el-form-item label="出厂日期:">
              <el-date-picker
                v-model="ruleForm.CCRQ"
                :picker-options="pickerBeginDateBefore"
                :disabled="jyModification"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd"
                class="inputSelect"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8" :offset="2">
            <el-form-item label="维保期限:" prop="BXQ">
              <el-input-number v-model.trim="ruleForm.BXQ" :disabled="jyModification" placeholder="请输入" controls-position="right" :min="0" :max="5 * 12" size="medium"></el-input-number>
              <span style="margin-left: 10px">个月</span>
            </el-form-item>
            <el-form-item label="设备编码:" prop="SBBM">
              <el-input v-model.trim="ruleForm.SBBM" :disabled="jyModification" clearable placeholder="设备编码"></el-input>
            </el-form-item>
            <el-form-item label="国标编码:" prop="GBBM">
              <el-input v-model.trim="ruleForm.GBBM" :disabled="jyModification" clearable placeholder="国标编码"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="2">
            <span class="title">其他信息：</span>
          </el-col>
          <el-col :span="8">
            <el-form-item label="所属合同:">
              <el-select v-model.trim="ruleForm.HT_ID" clearable :no-data-text="tiText1" :disabled="jyModification" filterable placeholder="资产所属合同" class="inputSelect">
                <el-option v-for="item in hetonOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="承建单位:">
              <el-select v-model.trim="ruleForm.CJDW" :no-data-text="tiText2" clearable filterable placeholder="选择承建单位" class="inputSelect">
                <el-option v-for="item in jgOptions2" :key="item.value" :label="item.label" :value="item.value"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="安装时间:">
              <el-date-picker v-model.trim="ruleForm.AZRQ" :picker-options="pickerBeginDateBefore" type="date" placeholder="选择日期" value-format="yyyy-MM-dd" class="inputSelect"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8" :offset="2">
            <el-form-item label="使用机构:" prop="SYDW">
              <!-- <el-input v-model.trim="ruleForm.SYDW" disabled placeholder="设备编码"></el-input> -->
              <el-select v-model.trim="ruleForm.SYDW" :no-data-text="tiText2" disabled placeholder="选择使用机构" class="inputSelect3">
                <el-option v-for="item in jgOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="运维单位:">
              <el-select v-model.trim="ruleForm.YWDW" :no-data-text="tiText2" clearable :disabled="jyModification" filterable placeholder="选择运维单位" class="inputSelect">
                <el-option v-for="item in jgOptions3" :key="item.value" :label="item.label" :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <div class="fooer_btn">
          <el-button size="medium" class="btnSizeStyle" @click="goBack">取 消</el-button>
          <el-button class="btnSizeStyle" type="primary" :loading="goliebiao" size="medium" @click="preservation(url, ruleForm)" v-preventReClick>保 存</el-button>
        </div>
      </el-form>
    </div>
  </div>
</template>
<script>
import { getUrl } from '@/utils/getUrl.js'
import { ziC, pinT, upload } from '@/utils/allUrl.js'
import { linkageCity } from '@/utils/linkageCity.js'
import { startLoading, endLoading } from '@/utils/loading.js'
import { timeLoad } from '@/assets/js/setTime'
// import { GetUrlByParamName } from '@/assets/js/GetUrlByParamName'
// import jointSelection from '@/components/JointSelection/index.vue'
export default {
  data: function () {
    return {
      addressOptions: [],
      // 修改资产ID
      xiuID: '',
      // 品牌
      ppmcOptions: [],
      // 合同
      hetonOptions: [],
      // 机构
      jgOptions: [],
      // 承建
      jgOptions2: [],
      // 运维
      jgOptions3: [],
      // 厂家
      cjOptions: [],
      // 加载
      loading: false,
      pickerBeginDateBefore: {
        // 设置只能选择到今天及以前的日期
        disabledDate(time) {
          return time.getTime() >= Date.now()
        },
      },
      ruleForm: {
        SBXLH: '',
        ZCMC: '',
        CJ: 1,
        PP: 3,
        XH: '',
        JWD: '',
        XQBM: '',
        XXDZ: '',
        CCRQ: '',
        AZRQ: '',
        ZCZT: '1',
        GBBM: '',
        SBBM: '',
        BXQ: 0,
        IP: '',
        SYDW: '',
        CJDW: '',
        YWDW: '',
        HT_ID: '',
        SF: '',
        CS: '',
        QX: '',
        XZJD: '',
      },
      rules: {
        SBXLH: [
          { required: true, message: '此次为必填项', trigger: 'blur' },
          // { pattern: /^[A-Za-z0-9-_]+$/, message: '请输入数字或者字母', trigger: 'blur' }
        ],
        ZCMC: [
          { required: true, message: '此次为必填项', trigger: 'blur' },
          { max: 255, message: '长度在 255 个字符之间', trigger: 'blur' },
        ],
        XQBM: [{ required: true, message: '此次为必填项', trigger: 'change' }],
        SYDW: [{ required: true, message: '此次为必填项', trigger: 'change' }],
        CJ: [{ required: true, message: '此次为必填项', trigger: 'change' }],
        PP: [{ required: true, message: '此次为必填项', trigger: 'change' }],
        XH: [{ required: true, message: '此次为必填项', trigger: 'blur' }],
        JWD: [{ pattern: /^[,.0-9]*$/, message: '请输入以英文逗号分隔的数字', trigger: 'blur' }],
        IP: [{ pattern: /^((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})(\.((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})){3}$/, message: '请输入正确的IP地址', trigger: 'blur' }],
        SBBM: [{ pattern: /^[A-Za-z0-9-_]+$/, message: '请输入数字或者字母', trigger: 'blur' }],
        GBBM: [{ pattern: /^[0-9]*$/, message: '请输入数字', trigger: 'blur' }],
        BXQ: [{ pattern: /^-?[0-9]\d*$/, message: '不能输入小数', trigger: 'blur' }],
      },
      url: '', // 跳转路径
      //  图片上传
      imgUrl: [],
      fileList: [], // 上传图片列表
      dialogVisible: false,
      dialogImageUrl: '', // 预览
      isoks: true, // 判断设备是否登录
      goliebiao: false, // 防重复点击
      xianxidizhi: '',
      jyModification: false,
      tiText1: '暂无数据', // 合同提示
      tiText2: '暂无数据', // 机构提示
      tiText3: '暂无数据', // 厂家提示
      tiText4: '暂无数据', // 品牌提示
      pageTimer: null,
    }
  },
  watch: {
    goliebiao(newVal, oldVal) {
      this.tableTimer = setTimeout(() => {
        if (this.goliebiao) {
          this.goliebiao = false
        }
      }, timeLoad)
    },
    loading(newVal, oldVal) {
      this.pageTimer = setTimeout(() => {
        if (this.loading) {
          this.loading = false
        }
      }, timeLoad)
    },
  },
  // components: { jointSelection },
  created() {
    // this.addressOptions = JSON.parse(getUrl('district'))
    this.ruleForm.SYDW = JSON.parse(getUrl('userconter')).zzjg_ID
    // const { content, url } = this.$route.params
    const { url } = this.$route.query
    this.url = `${url}`
  },
  mounted() {
    // var date = new Date()
    // let hour = date.getHours() // 时
    // hour = hour < 10 ? '0' + hour : hour // 如果只有一位，则前面补零
    // let minute = date.getMinutes() // 分
    // minute = minute < 10 ? '0' + minute : minute // 如果只有一位，则前面补零
    // let second = date.getSeconds() // 秒
    // second = second < 10 ? '0' + second : second // 如果只有一位，则前面补零
    // var nowDate = `${hour}:${minute}:${second}`
    // console.log('进来了', nowDate)
    const { content, url } = this.$route.query
    // 禁用修改
    if (url === 'networkAccessList') {
      // 主机备案列表
      this.jyModification = false
      this.getZcdj(content)
    } else {
      // 资产管理
      this.jyModification = true
      this.getBjzc(content)
    }
    // 获取合同
    this.getht()
    // 获取品牌
    this.getpp()
    // 获取机构
    this.getjg()
    // 获取厂家
    this.getcj()
  },
  methods: {
    // 安装地址获取
    async getAdress(code) {
      const params = new URLSearchParams()
      params.append('streetCodeEx', code)
      const { data: res } = await this.$http.post(`${pinT}district/find`, params)
      if (res.code !== '0000') {
        return
      }
      var list = []
      // console.log(res.data)
      res.data.forEach((item) => {
        // console.log(item)
        list.push({
          label: item.provinceName, // 河北省
          level: 'province',
          value: Number(item.provinceCode), // '130000'
          children: [
            {
              label: item.cityName, // 石家庄市
              level: 'city',
              value: Number(item.cityCode), // 130100
              children: [
                {
                  label: item.areaName, // 长安区
                  level: 'area',
                  value: Number(item.areaCode), // 130102
                  children: [
                    {
                      label: item.streetName, // 长丰街道
                      level: 'street',
                      value: Number(item.streetCodeEx), // 13010201
                    },
                  ],
                },
              ],
            },
          ],
        })
      })
      this.addressOptions = list
      // console.log('-------', this.addressOptions)
      this.ruleForm.XQBM = Number(code) // 辖区
    },
    preservation(url, ruleForm) {
      this.goliebiao = true
      // var a = setTimeout(() => {
      //   this.goliebiao = false
      // }, 10000)
      // console.log(url)
      switch (url) {
        case 'networkAccessList':
          // 主机备案列表
          this.submitZj(ruleForm)
          break
        default:
          this.submitBj(ruleForm)
          break
      }
    },
    // 主机备案保存
    async submitZj(ruleForm) {
      this.$refs.ruleForm.validate(async (valid) => {
        if (!valid) {
          this.goliebiao = false
          this.$message({
            type: 'error',
            message: '请填写正确的信息',
            center: true,
          })
          return
        }
        // console.log(this.ruleForm)
        const { SBXLH, ZCMC, CJ, PP, XH, JWD, SF, CS, QX, XZJD, XXDZ, CCRQ, AZRQ, ZCZT, GBBM, SBBM, BXQ, IP, SYDW, CJDW, YWDW, HT_ID, ICCID } = this.ruleForm
        const params = new URLSearchParams()
        params.append('ZCLX', 53)
        params.append('SBXLH', SBXLH)
        params.append('ZCMC', ZCMC)
        params.append('CJ', CJ)
        params.append('PP_ID', PP)
        params.append('XH', XH)
        params.append('XXDZ', XXDZ || '')
        params.append('CCRQ', CCRQ || '')
        params.append('AZRQ', AZRQ || '')
        params.append('ZCZT', ZCZT || '')
        params.append('GBBM', GBBM || '')
        params.append('SBBM', SBBM || '')
        params.append('BXQ', BXQ || 0)
        params.append('IP', IP || '')
        params.append('SYDW', SYDW || 0)
        params.append('CJDW', CJDW || 0)
        params.append('YWDW', YWDW || 0)
        params.append('imgs', JSON.stringify(this.imgUrl))
        params.append('HT_ID', HT_ID || 0)
        params.append('SF', SF)
        params.append('CS', CS)
        params.append('QX', QX)
        params.append('SSQ_NO', XZJD)
        params.append('XZJD', XZJD)
        params.append('XQBM', XZJD)
        params.append('ICCID', ICCID)
        const d = JWD.split(',')
        params.append('JD', d[0] || '')
        params.append('WD', d[1] || '')
        // console.log('-----', d[0], d[1])
        // console.log(params, JWD)
        const { data: res } = await this.$http.post(`${ziC}zcgl/insertZiChan`, params)
        this.goliebiao = false
        // clearTimeout(a)
        switch (res.code) {
          case '0000':
            this.$message({
              type: 'success',
              message: res.message,
              center: true,
            })
            this.goBack()
            break
          default:
            this.$message({
              type: 'error',
              message: res.message,
              center: true,
            })
            break
        }
      })
    },
    async submitBj(ruleForm) {
      this.$refs.ruleForm.validate(async (valid) => {
        if (!valid) {
          this.goliebiao = false
          this.$message({
            type: 'error',
            message: '请填写正确的信息',
            center: true,
          })
          return
        }
        const { SBXLH, ZCMC, CJ, PP, XH, JWD, XQBM, XXDZ, CCRQ, AZRQ, ZCZT, GBBM, SBBM, BXQ, IP, SYDW, CJDW, YWDW, HT_ID } = this.ruleForm
        const params2 = new URLSearchParams()
        params2.append('ZCLX', 53)
        params2.append('ID', this.xiuID)
        params2.append('SBXLH', SBXLH)
        params2.append('ZCMC', ZCMC)
        params2.append('CJ', CJ)
        params2.append('PP_ID', PP)
        params2.append('XH', XH)
        params2.append('XXDZ', XXDZ)
        params2.append('CCRQ', CCRQ)
        params2.append('AZRQ', AZRQ)
        params2.append('ZCZT', ZCZT)
        params2.append('GBBM', GBBM)
        params2.append('SBBM', SBBM)
        params2.append('BXQ', BXQ || 0)
        params2.append('IP', IP)
        params2.append('SYDW', SYDW || 0)
        params2.append('CJDW', CJDW || 0)
        params2.append('YWDW', YWDW || 0)
        params2.append('imgs', JSON.stringify(this.imgUrl))
        params2.append('HT_ID', HT_ID || 0)
        if (typeof XQBM !== 'number') {
          const s = (XQBM + '').substr(0, 2) + '0000'
          const c = (XQBM + '').substr(0, 4) + '00'
          const x = (XQBM + '').substr(0, 6)
          params2.append('SF', s)
          params2.append('CS', c)
          params2.append('QX', x)
          if ((XQBM + '').length > 6) {
            params2.append('XZJD', XQBM)
            params2.append('SSQ_NO', XQBM)
          } else {
            params2.append('SSQ_NO', x)
          }
          // params2.append('SSQ_NO', XQBM[XQBM.length - 1])
          // if (XQBM.length === 3) {
          //   params2.append('SF', XQBM[0])
          //   params2.append('CS', XQBM[1])
          //   params2.append('QX', XQBM[2])
          //   params2.append('SSQ_NO', XQBM[2])
          // } else if (XQBM.length === 4) {
          //   params2.append('SF', XQBM[0])
          //   params2.append('CS', XQBM[1])
          //   params2.append('QX', XQBM[2])
          //   params2.append('XZJD', XQBM[3])
          //   params2.append('SSQ_NO', XQBM[3])
          // }
        } else {
          // params2.append('SSQ_NO', XQBM)
          const s = (XQBM + '').substr(0, 2) + '0000'
          const c = (XQBM + '').substr(0, 4) + '00'
          const x = (XQBM + '').substr(0, 6)
          params2.append('SF', s)
          params2.append('CS', c)
          params2.append('QX', x)
          if ((XQBM + '').length > 6) {
            params2.append('XZJD', XQBM)
            params2.append('SSQ_NO', XQBM)
          } else {
            params2.append('SSQ_NO', x)
          }
        }
        const d = JWD.split(',')
        params2.append('JD', d[0] | '')
        params2.append('WD', d[1] | '')
        const { data: res } = await this.$http.post(`${ziC}zcgl/updateZiChan`, params2)
        if (res.code === '0014') {
          return ''
        } else if (res.code !== '0000') {
          // clearTimeout(a)
          this.goliebiao = false
          return this.$message({
            type: 'error',
            message: res.message,
            center: true,
          })
        }
        this.$message({
          type: 'success',
          message: res.message,
          center: true,
        })
        this.goBack()
      })
    },
    async getZcdj(content) {
      clearTimeout(this.pageTimer)
      this.loading = true
      // 主机备案列表
      const params = new URLSearchParams()
      params.append('SBXLH', content)
      const { data: res } = await this.$http.post(`${ziC}zcgl/selectZhuJi`, params)
      this.loading = false
      if (res.code === '0000') {
        const list = res.data[0]
        this.getAdress(list.xzjd) // 获取辖区
        const { qwcode, name, model, sf, cs, qx, xzjd, address, productiondate, international, iccid, JWD, ip } = list
        this.ruleForm.SBXLH = qwcode // 序列码
        this.ruleForm.ZCMC = name // 资产名称
        this.ruleForm.XH = model // 型号
        // this.ruleForm.XQBM = xzjd // 辖区
        this.ruleForm.SF = sf
        this.ruleForm.CS = cs
        this.ruleForm.QX = qx
        this.ruleForm.XZJD = xzjd + ''
        this.ruleForm.XXDZ = address // 详细地址
        this.ruleForm.CCRQ = productiondate // 出厂日期
        this.ruleForm.GBBM = international // 国标编码
        this.ruleForm.BXQ = 0 // 维保期限
        this.ruleForm.ICCID = iccid // iccid
        this.ruleForm.JWD = JWD // 坐标
        this.ruleForm.IP = ip // ip地址
      } else {
        this.$message.error(res.message)
      }
    },
    async getBjzc(content) {
      // 资产管理
      const params = new URLSearchParams()
      params.append('ID', content)
      const { data: res } = await this.$http.post(`${ziC}zcgl/selectByID`, params)
      switch (res.code) {
        case '0000':
          this.getAdress(res.data.ssq_NO)
          this.xiuID = res.data.id
          // this.ruleForm = {
          this.ruleForm.SBXLH = res.data.sbxlh
          this.ruleForm.ZCMC = res.data.zcmc
          this.ruleForm.CJ = 1
          this.ruleForm.PP = 3
          this.ruleForm.XH = res.data.xh
          this.ruleForm.JWD = res.data.jd + ',' + res.data.wd
          // XQBM= res.data.ssq_NO
          this.ruleForm.XXDZ = res.data.xxdz
          this.ruleForm.CCRQ = res.data.ccrq || ''
          this.ruleForm.AZRQ = res.data.azrq || ''
          this.ruleForm.ZCZT = res.data.zczt
          this.ruleForm.GBBM = res.data.gbbm
          this.ruleForm.SBBM = res.data.sbbm
          this.ruleForm.BXQ = res.data.bxq
          this.ruleForm.IP = res.data.ip
          this.ruleForm.SYDW = res.data.sydw
          this.ruleForm.CJDW = res.data.cjdw === 0 ? '' : res.data.cjdw
          console.log(res.data.ywdw)
          console.log(this.jgOptions3)
          this.ruleForm.YWDW = res.data.ywdw === 0 ? '' : res.data.ywdw
          this.ruleForm.HT_ID = res.data.ht_ID === 0 ? '' : res.data.ht_ID
          this.ruleForm.SF = res.data.sf
          this.ruleForm.CS = res.data.cs
          this.ruleForm.QX = res.data.qx
          this.ruleForm.XZJD = res.data.xzjd
          // }
          // console.log(this.ruleForm)
          break
        default:
          break
      }
    },
    // 转换时间格式
    detaTiem(value) {
      if (value) {
        const dt = new Date(value)
        const y = dt.getFullYear()
        const m = (dt.getMonth() + 1 + '').padStart(2, 0)
        const d = (dt.getDate() + '').padStart(2, 0)
        return `${y}-${m}-${d}`
      } else {
        return ''
      }
    },
    // 获取合同
    async getht() {
      const { data: res } = await this.$http.post(`${pinT}htgl/list`)
      switch (res.code) {
        case '0000':
          var arr = []
          res.data.list.forEach((item) => {
            const k = {
              value: item.id,
              label: item.htmc,
            }
            arr.push(k)
          })
          this.hetonOptions = arr
          break
        default:
          this.hetonOptions = []
          this.tiText1 = res.message
          break
      }
    },
    // 获取品牌
    async getpp() {
      const { data: res } = await this.$http.post(`${ziC}pp/list`)
      const arr = []
      if (res.code !== '0000') {
        this.ppmcOptions = []
        this.tiText4 = res.message
      } else {
        res.data.list.forEach((item) => {
          const k = {
            value: item.id,
            label: item.ppmc,
          }
          arr.push(k)
        })
        this.ppmcOptions = arr
      }
    },
    // 获取机构
    async getjg() {
      const { data: res } = await this.$http.post(`${pinT}zzjg/list`)
      console.log(res)
      const arr = [] // 全部
      const arr2 = [] // 承建
      const arr3 = [] // 运维
      if (res.code !== '0000') {
        this.jgOptions = []
        this.jgOptions2 = []
        this.jgOptions3 = []
        this.tiText2 = res.message
      } else {
        res.data.list.forEach((item) => {
          if (item.jglx === 4) {
            const k3 = {
              value: item.id,
              label: item.jgmc,
            }
            arr3.push(k3)
          } else if (item.jglx === 3) {
            const k2 = {
              value: item.id,
              label: item.jgmc,
            }
            arr2.push(k2)
          }
          const k = {
            value: item.id,
            label: item.jgmc,
          }
          arr.push(k)
        })
        console.log(arr3)
        this.jgOptions = arr
        this.jgOptions2 = arr2
        this.jgOptions3 = arr3
      }
    },
    // 获取厂家
    async getcj() {
      const params = new URLSearchParams()
      params.append('cxlx', 'cj')
      const { data: res } = await this.$http.post(`${pinT}zzjg/list`, params)
      const arr = []
      if (res.code !== '0000') {
        this.cjOptions = []
        this.tiText3 = res.message
      } else {
        res.data.list.forEach((item) => {
          const k = {
            value: item.id,
            label: item.jgmc,
          }
          arr.push(k)
        })
        // console.log(arr)
        this.cjOptions = arr
      }
    },
    // 删除图片
    handleRemove(a) {
      const index = this.imgUrl.findIndex((item) => item.uid === a.uid)
      this.imgUrl.splice(index, 1)
    },
    // 添加图片
    async lalal(el) {
      let videoSize = el.size / (1024 * 1024) // 转成M格式
      videoSize = videoSize.toFixed(1) // 保留小数点后一位
      if (videoSize > 2) {
        const dele = this.$refs.upload.uploadFiles
        const index = dele.findIndex((item) => item.uid === el.uid)
        dele.splice(index, 1)
        // this.$refs.upload.uploadFiles
        return this.$message({
          type: 'error',
          message: '图片超过最大限制2M',
          center: true,
        })
      } else {
        startLoading(document.getElementById('uploadtu8'))
        const file = el.raw
        const fd = new FormData()
        let arr = {}
        fd.append('file', file) // 传文件
        fd.append('type', 0) // 传文件
        const { data: res } = await this.$http.post(`${upload}`, fd)
        endLoading()
        if (res.code === '0000') {
          res.data.forEach((item) => {
            arr = {
              uid: el.uid,
              url: item,
            }
          })
          this.imgUrl.push(arr)
        } else {
          return this.$message({
            type: 'error',
            message: res.message,
            center: true,
          })
        }
      }
    },
    // 预览
    handlePictureCardPreview(e) {
      this.dialogImageUrl = e.url
      this.dialogVisible = true
    },
    goBack() {
      // console.log('------', this.url)
      var params = {}
      switch (this.url) {
        case 'networkAccessList': // 主机备案管理
          params = {
            // 传递参数
            pingpai: this.$route.query.pingpai,
            nameList: this.$route.query.nameList,
          }
          break
        case 'propertyList':
          params = {
            // 传递参数
            pingpai: this.$route.query.pingpai, // 品牌
            zicanglx: this.$route.query.zicanglx, // 资产类型
            zicanZT: this.$route.query.zicanZT, // 资产状态
            azTime: this.$route.query.azTime, // 安装时间
            sous: this.$route.query.sous, // 资产名称/ip/sn号
            // this.currentPage = this.$route.params.currentPage
            // this.pageSize = this.$route.params.pageSize
          }
          // 资产管理
          break
      }
      this.$router.push({
        name: this.url,
        params: params,
      })
    },
    async lazyLoadAdd(node, resolve) {
      const user = JSON.parse(getUrl('userconter'))
      if (node.level === 0) {
        return resolve(await linkageCity(user.id, node.level + 1))
      } else if (node.level === 1) {
        return resolve(await linkageCity(user.id, node.level + 1, node.value))
      } else if (node.level === 2) {
        return resolve(await linkageCity(user.id, node.level + 1, node.value))
      } else if (node.level === 3) {
        return resolve(await linkageCity(user.id, node.level + 1, node.value, node.label))
      }
    },
    // pingguanbi(val) {
    //   const { type, xqbmArr, cityVal } = val
    //   if (xqbmArr.length !== 0) {
    //     this.ruleForm.XQBM = xqbmArr
    //   }
    //   this.xianxidizhi = cityVal || this.xianxidizhi
    //   // console.log(type, xqbm, xqbmArr, cityVal)
    //   this.JointSelection.dialogWorkOrder = type
    // }
  },
}
</script>
<style lang="scss" scoped>
::v-deep .inputSelect3 .el-input__suffix {
  opacity: 0;
}
.userBox {
  .el-row {
    padding-top: 20px;
    &:first-child {
      padding-top: 0;
    }
    // padding: 15px 25px 0 25px;
    border-bottom: 1px solid #f2f2f2;
    .title {
      display: block;
      height: 38px;
      line-height: 38px;
      color: rgba(89, 89, 89, 1);
      font-size: 15px;
      font-weight: 600;
    }
    .el-form-item {
      .inputSelect {
        width: 260px;
      }
      .inputSelect2 {
        width: 390px;
      }
      .inputSelect3 {
        width: 260px;
      }
      .jinDuTitle {
        height: 18px;
        line-height: 22px;
        color: #c0c4cc;
      }
      .iconBtn {
        margin-left: 10px;
        font-size: 15px;
        color: rgba(187, 187, 187, 1);
        cursor: pointer;
      }
      .DuFen {
        display: flex;
        justify-content: space-around;
        align-items: center;
        .btnGs {
          margin: 0 10px;
        }
      }
      .el-upload__tip {
        font-size: 12px;
        color: #a1a3a8;
        margin-top: 7px;
        padding-left: 10px;
      }
    }
    .pilian_btn {
      position: relative;
      width: 258%;
      top: -25px;
      left: 65px;
      padding: 0 18px;
      background-color: #fffbe6;
      > div {
        height: 30px;
        line-height: 30px;
        color: #e28b02;
        .xiaBtn {
          padding: 0;
        }
      }
    }
    .konBox {
      height: 68px;
    }
    .shebeima {
      padding: 0;
      margin-bottom: 10px;
    }
    .shebeima2 {
      padding: 0;
      margin: 0;
    }
  }
  .fooer_btn {
    margin: 10px 0;
    display: flex;
    justify-content: flex-end;
  }
}
// 禁止输入字体变为黑色
::v-deep .el-input.is-disabled .el-input__inner {
  color: #000;
}
::v-deep .el-textarea.is-disabled .el-textarea__inner {
  color: #000;
}
</style>
